<template>
  <el-dialog :title="`${form.versionId ? '修改' : '添加'}检查项版本`" :visible.sync="show" :close-on-click-modal="false" :show-close="!btnLoading" width="500px" @closed="$refs.form.resetFields()">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item prop="versionId" class="hide" />
      <el-form-item label="版本号" prop="versionCode"><el-input v-model.trim="form.versionCode" placeholder="请输入版本号" :maxlength="100" :disabled="!!form.versionId" /></el-form-item>
      <el-form-item label="版本名称" prop="versionName"><el-input v-model.trim="form.versionName" placeholder="请输入版本名称" :maxlength="200" /></el-form-item>
      <el-form-item label="生效时间" prop="startDate">
        <el-date-picker type="datetime" placeholder="选择日期" v-model="form.startDate" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%" />
      </el-form-item>
      <el-form-item label="失效时间" prop="endDate">
        <el-date-picker type="datetime" placeholder="选择日期" v-model="form.endDate" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%" />
      </el-form-item>
      <el-form-item label="备注" prop="remark"><el-input v-model="form.remark" type="textarea" placeholder="请输入内容" :maxlength="255" /></el-form-item>
      <el-form-item label="是否启用" prop="isEnable"><el-switch v-model="form.isEnable" :active-value="1" :inactive-value="0" /></el-form-item>
    </el-form>
    <div slot="footer">
      <el-button type="primary" :loading="btnLoading" @click="btnSubmit">确 定</el-button>
      <el-button :disabled="btnLoading" @click="show = false">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
// 添加或修改检查项版本
import { nameRule } from '@/utils/validate'
import { editFormMixin } from '@/utils/mixin'
import { addVersion, updateVersion } from '@/api/checkScore/cqEval'
export default {
  mixins: [editFormMixin],
  data() {
    return {
      primaryKey: 'versionId',
      addApi: addVersion,
      updateApi: updateVersion,
      form: {
        versionId: '',
        versionCode: '',
        versionName: '',
        startDate: '',
        endDate: '',
        remark: '',
        isEnable: 1
      },
      rules: {
        versionCode: [{ required: true, message: '请输入版本号' }, nameRule],
        versionName: [{ required: true, message: '请输入版本名称' }, nameRule],
        startDate: [{ required: true, message: '请选择生效时间' }],
        endDate: [{ required: true, message: '请选择失效时间' }]
      }
    }
  }
}
</script>
